<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <include file="Public:resource"/>
    <title>投诉建议</title>
</head>
<body>
<div class="container">
    <include file="Public:top" title="投诉建议"/>
    <form id="complaint-form">
        <div class="row" style="margin-top: 20px;">
            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 medium align-to-input" align="left">
                建议类别
            </div>
            <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
                <select id="type" name="type" class="select">
                    <option value="漏水举报" class="option">漏水举报</option>
                    <option value="违章举报" class="option">违章举报</option>
                    <option value="服务投诉" class="option">服务投诉</option>
                    <option value="用户建议" class="option">用户建议</option>
                </select>
            </div>
        </div>

        <div class="row" style="margin-top:10px;">
            <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 medium" align="left">
                投诉内容
            </div>
            <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
                <textarea name="content" id="content" style="width:100%;border: darkgray solid 1px;" rows="5"
                          placeholder="请输入内容"></textarea>
            </div>
        </div>

        <div class="row" style="margin-top: 20px;">
            <div class="col-xs-12 col-sm-12 col-mg-12 col-md-12">
                <div><input type="button" class="btn btn-lg btn-block jss-button"
                            onclick="onSubmit() " value="提交"/>
                </div>
            </div>
        </div>

    </form>
    <include file="Public:progress" hint="提交中..."/>
    <include file="Public:message"/>
</div>
<script>
    //提交投诉建议
    function onSubmit() {
        if ($("#type").val() == '') {
            alert("请选择类别!");
            return;
        }
        if ($("#content").val() == '') {
            alert("请填写内容!");
            return;
        }
        showProgress();
        $.ajax({
            type: 'post',
            dataType: 'json',
            url: "{:U('Complaint/add')}",
            data: $("#complaint-form").serialize(),
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            success: function (json) {
                hideProgress();
                if (json.status == 'success') {
                    showMessage(json.msg, 1000);
                    clearForm();
                    setTimeout(function () {
                        window.location.href = "{:U('index')}";
                    }, 1000);
                } else {
                    alert(json.msg);
                }
            },
            error: function (msg) {
                hideProgress();
                alert("提交失败,请检查网络!");
            }
        })
    }
    //清空表单
    function clearForm() {
        $("#type").val('');
        $("#content").val('');
    }
</script>
</body>
</html>